package com.onpositive.collections;

import java.util.List;

public class LastValueCalculator implements IMemberValueCalculator {

	private static final long serialVersionUID = 5221026090918746713L;

	@Override
	public Object calculateValue(IObjectCollection collection,ICollectionMember<?> member) {
		
		List<ICollectionDelta<?>> history = collection.getCompleteHistory();
		int size = history.size() ;
		Object value = null ;
		for( int i = size ; i > 0 ; i-- ){
			ICollectionDelta<?> delta = history.get(i-1);			
			value = delta.getValue(member);
			if(value != null)
				break ;
		}		
		return value ;
	}

}
